import { fetchUserInfo } from '@/api/system/user'
import { useEffect, useState } from 'react'
import { IUserData, IUserInfo } from '@/interface/user'

export default function useUserInfo() {
  const [userData, setUserData] = useState<IUserData>({
    menu: [],
    activeUsers: {} as IUserInfo,
    storeInfo: {},
    permission: [],
  })
  const [loading, setLoading] = useState(false)

  const fetchData = async () => {
    const result = await fetchUserInfo()
    setUserData(result)
  }

  useEffect(() => {
    setLoading(true)
    fetchData().then((() => {
      setLoading(false)
    }))
  }, [])

  return { loading, userData, setUserData }
}
